import { commission,recommendList,transactionRecord } from "../../api/activity"
import user from "../../../utils/user"
import { setSignInMode } from "../../../api/app"
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabIndex:0,
        incomeNum:{},//收入
        customerList:[],//客户列表
        topList:[],
        pageSize:20,
        pageNum:1,
        hasNextPage:false,
        topListLength:'',
        iCount:''
    },
    async onLoad(options) {
        await user.waitLogin().then(async()=>{
            this.commission()
            this.getRecommendList()
        })
    },
    onShow(){
        this.getTransactionRecord()
    },
    onHide(){
        console.log('调用啦吗')
        clearInterval(this.data.iCount);
    },
    onRuleTabs(){
        this.setData({
            tabIndex:1
        })
    },
    onRonusTabs(){
        this.setData({
            tabIndex:0
        })
    },
    // 总收入
    commission(){
        commission().then(res=>{
            this.setData({
                incomeNum:res
            })
        })
    },
    // 客户列表
    getRecommendList(){
        recommendList({
            pageSize:this.data.pageSize,
            pageNum:this.data.pageNum
        }).then(res=>{
            if(!res.hasNextPage){
                this.data.hasNextPage = false
                //hasNextPage
            }else{
                this.data.hasNextPage = true
            }
            let arr = []
            arr.push(...this.data.customerList)
            arr.push(...res.list)
            this.setData({
                customerList:arr
            })
        })
    },
    // 头部滚动条
    getTransactionRecord(){
        transactionRecord().then(res=>{
            console.log(res,'res')
            res.forEach((item,index)=>{
                res[index].userName = item.userName.substring(0,1) + ((item.userName.length == 2) ? '*' : '**')
            })
            this.setData({
                topList:res,
                topListLength:res.length
            })
        })
    },
    // 滚动到底部啦
    threshold(){
        console.log('到底部啦')
        if(!this.data.hasNextPage){
            return
        }
        this.setData({
            pageNum:this.data.pageNum+=1
        })
        this.getRecommendList()
    },
    // go分享
    goShare(){
        wx.navigateTo({
          url: '/packageActivity/pages/posters-work/posters-work',
        })
    }
})